package client.comm.baoding.ui.vm

import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import client.comm.baoding.dialog.MsgTitleDialog
import client.comm.baoding.ui.TextContentActivity
import client.comm.baoding.ui.XgmmActivity
import client.comm.baoding.ui.XgzjmmActivity
import client.comm.baoding.ui.viewmodel.MiddleVm
import client.comm.baoding.utils.ReadAssetsUtil
import client.comm.commlib.ContextProvider
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret

class AccountSafeViewModel (app: Application) : MiddleVm(app) {

    val isShowing = MutableLiveData<Boolean>(false)
    val call = MutableLiveData<JsonResult<Ret>>()


    /**
     * 修改密码
     */
    fun changePwd() {
        ContextProvider.get().activity?.apply {
            startActivity(Intent(this, XgmmActivity::class.java))
        }
    }

    /**
     * 修改交易密码
     */
    fun changeJymm() {
        ContextProvider.get().activity?.apply {
            startActivity(Intent(this, XgzjmmActivity::class.java))
        }
    }

    /**
     * 注销
     */
    fun logout(){
        ContextProvider.get().activity?.apply {
            MsgTitleDialog(this).apply {
                title = "注销后，数据不可追回！\n是否确认注销？"
                ok = {
                    logoutCall()
                }
                okTxt = "确认"
                cancleTxt = "取消"
            }.show()

        }
    }

    fun logoutCall() {
        isShowing.value = true
        hold({
            server.user_out()
        }, success = {
            call.value = it
        }, complete = {
            isShowing.value = false
        })
    }


}
